home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 93win / data1.cab / DLL_Toolkit / Source / HTBIntegerSum / HTBIntegerSum.cpp next >
Encoding:
C/C++ Source or Header  |  2005-03-02  |  1.9 KB  |  72 lines

  1. // HTBIntegerSum
  2.  
  3. // example for calling _stdcall dll from _cdecl dll
  4.  
  5. //        High Tech BASIC, Copyright (C) TransEra Corp 2000, All Rights Reserved.
  6.  
  7.  
  8.  
  9. #include <windows.h>
  10.  
  11.  
  12. typedef int (WINAPI * lpIntSum)(int,int);        // standard call type def for function
  13.  
  14.  
  15. lpIntSum fpIntSum = NULL;                        // used to hold function pointer
  16.  
  17. HINSTANCE hIntSum;                                // used to hold handle to DLL
  18.  
  19.  
  20. extern "C" 
  21. {
  22.  
  23. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  24.  
  25. // Function name    : InitDLL
  26. // Description        : initalize function pointer for IntegerSum function in IntegerSum.dll
  27. // Return type        : BOOL 
  28. BOOL InitDLL()
  29. {    BOOL result = TRUE;
  30.  
  31.     hIntSum = LoadLibrary("IntegerSum.dll");    // load DLL
  32.  
  33.     if (hIntSum != NULL)                        // if load did not fail
  34.     {    fpIntSum = (lpIntSum)GetProcAddress(hIntSum,"IntegerSum");    // get pointer to function
  35.  
  36.         if (fpIntSum == NULL)                    // if pointer is bad
  37.         {    result = FALSE;                        // set to return an error
  38.         }
  39.     }
  40.     else
  41.     {    result = FALSE;                            // if load failed set to return an error
  42.     }
  43.  
  44.     return(result);
  45. }
  46.  
  47.  
  48. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  49.  
  50.  
  51.  
  52. // Function name    : IntegerSum
  53. // Description        : return the sum of two ints
  54. // Return type        : int 
  55. // Argument         : int val1
  56. // Argument         : int val2
  57. int _cdecl Integersum(int val1, int val2)
  58. {    if (fpIntSum == NULL)                        // if we have no function pointer yet
  59.     {    BOOL result = InitDLL();                // go load DLL and get one
  60.  
  61.         if (!result)                            // if failed getting function pointer
  62.         {    MessageBox(NULL,"Error Loading __stdcall DLL","Error",MB_OK);
  63.             return(0);                            // return a zero -- zero could also be a vaild sum!!!
  64.         }
  65.     }
  66.  
  67.     return(fpIntSum(val1,val2));                // Call standard Call function and return result
  68. }
  69.  
  70.  
  71.  
  72. } // end extern "C"